What is airbnb-js-shims?
The airbnb-js-shims package is a collection of JavaScript shims and polyfills used by Airbnb. It helps in ensuring that JavaScript code runs smoothly across different environments by providing compatibility for features that may not be available in older browsers or certain environments. This package is particularly useful for developers looking to support a wide range of browsers without having to worry about the availability of modern JavaScript features.
What are airbnb-js-shims's main functionalities?
Array and Object methods
Provides polyfills for modern Array and Object methods like Array.prototype.find and Object.assign, allowing developers to use these methods even in environments that do not natively support them.
[].find(item => item === 2); Object.assign({}, { a: 1 });
Promise support
Includes a polyfill for Promises, enabling asynchronous operations support in environments where Promises are not natively available.
new Promise((resolve, reject) => { resolve('Success'); });
String methods
Adds support for newer String methods such as startsWith and includes, making string manipulation tasks easier and more intuitive.
'hello'.startsWith('he'); 'food'.includes('oo');
Other packages similar to airbnb-js-shims
core-js
Core-js is a modular standard library for JavaScript, providing polyfills for many ECMAScript features. It covers more ground than airbnb-js-shims by including polyfills for features like symbols, sets, and maps. Core-js is often used in environments where a comprehensive set of polyfills is required.
babel-polyfill
Babel-polyfill (now deprecated in favor of @babel/preset-env) was a package that provided a wider range of JavaScript language features by including core-js and regenerator-runtime. Compared to airbnb-js-shims, babel-polyfill was more focused on supporting the compilation process of modern JavaScript to older versions, making it a more comprehensive solution for developers using Babel.
airbnb-js-shims
JS language shims used by Airbnb.
Just require/import airbnb-js-shims
, and the environment will be shimmed.
import 'airbnb-js-shims';
Included shims
Targeting versions
If you do not need to support older browsers, you can pick a subset of ES versions to target. For example, if you don't support pre-ES5 browsers, you can start your shims with ES2015 by requiring/importing the specific target file. This will shim the environment for that version and upward.
import 'airbnb-js-shims/target/es2015';
Included targets
airbnb-js-shims/target/es5
(default)airbnb-js-shims/target/es2015
airbnb-js-shims/target/es2016
airbnb-js-shims/target/es2017
airbnb-js-shims/target/es2018
airbnb-js-shims/target/es2019